#pragma once

#include "manipulatorbase.h"
#include <osg\Vec3>
#include "controlcenter_global.h"
#include <osgGA\AnimationPathManipulator>
#include <osgViewer\View>

namespace ControlCenter
{
	class AnimationPathManipulatorExt:public osgGA::AnimationPathManipulator
	{
	public:
		AnimationPathManipulatorExt(osgGA::CameraManipulator* premanipulator,osg::AnimationPath* p = NULL);
		void setPreManipulator(osgGA::CameraManipulator* premanipulator);
		virtual bool handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter& us);
		virtual void restartAnimation();
	protected:
		virtual ~AnimationPathManipulatorExt();
		void handleFrameExt(osgGA::GUIActionAdapter& us);
		osgGA::CameraManipulator*									_preManipulator;
		osg::Timer_t												_startTick;
		osgViewer::View*											_mainView;
	};

	class CONTROLCENTER_EXPORT CameraAnimationManipulator:public ManipulatorBase
	{
	public:
		CameraAnimationManipulator(osgViewer::View* view);
		bool handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter& us);
		virtual void setByMatrix(const osg::Matrixd& matrix){}
		virtual void setByInverseMatrix(const osg::Matrixd& matrix){}
		osg::Matrixd getMatrix() const;
		osg::Matrixd getInverseMatrix() const;
		virtual void enableManipulator();
		virtual void disenableManipulator();
		virtual void setToolAction(ActionData* action);
		virtual void getLookAt(osg::Vec3& eye,osg::Vec3& center,osg::Vec3& up,float& distance);
		virtual void setLookAt(const osg::Vec3& eye,const osg::Vec3& center,const osg::Vec3& up,float distance,bool rightaway);
		virtual void setLookAt(const osg::Vec3& vec,const osg::Vec3& rota,float upangle,float sideangle,float distancevalue
			,bool rightaway){}
		virtual void home(const osgGA::GUIEventAdapter& ,osgGA::GUIActionAdapter&);
	protected:
		virtual ~CameraAnimationManipulator();
		void switchCameraAnimation(int cameraindex);
		void switchCameraAnimation(const QString& animationname);
		void switchCameraAnimation(CoreBase::ActorBase* animationactor);
		void nextAnimationPointAtti();
		void updateCamera();
		void resetSpeed(bool isplaying = false);
		virtual void keyDown(const osgGA::GUIEventAdapter* ea0,osgGA::GUIActionAdapter& us);
		virtual void keyUp(const osgGA::GUIEventAdapter* ea0,osgGA::GUIActionAdapter& us);
		virtual void mouseDrag(const osgGA::GUIEventAdapter* ea0,const osgGA::GUIEventAdapter* ea1,
			const osgGA::GUIEventAdapter* key0,const osgGA::GUIEventAdapter* key1);
		void _frame();
		int												_moveFrameNum;
		QVector<QVector<osg::Vec3>>						_allAttitude;
		QVector<int>									_allFrameNumberVector;
		int												_currentAttitudeIndex;
		int												_currentCameraIndex;
		QList<CoreBase::ActorBase*>						_allCameraAnimationActors;
		osg::Vec3										_eyeVecInterpolation;
		osg::Vec3										_centerVecInterpolation;
		osg::Vec3										_upVecInterpolation;
		osg::Matrixd									_inverseMatrix;
		float											_currentMaxFramenumber;
		osg::Vec3										_preEye;
		osg::Vec3										_preCenter;
		osg::Vec3										_preUp;
		osg::ref_ptr<AnimationPathManipulatorExt>		_animationManipulatorExt;
		QString											_currentAnimationType;
		bool											_freeDirection;
		bool											_autoSwitchAnimation;
		float											_speed;
		osgViewer::View*								_mainView;
		double											_leftMouseRotationRate;
		double											_rightMouseRotationRate;
		double											_upDisctence;
		double											_directionRotationRate;
		osg::Vec3										_position;
		osg::Vec3										_direction;
		QVector<float>									_speedDefine;
	};
}